package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.Sdyx;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.SdyxMapper;
import com.gfxy.modules.items.service.ISdyxService;
import com.gfxy.modules.items.vo.*;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 1+x试点与运行
 * @Author: jeecg-boot
 * @Date:   2021-09-30
 * @Version: V1.0
 */
@Service
public class SdyxServiceImpl extends AbstractProjectServiceImpl<SdyxMapper, Sdyx> implements ISdyxService {
	protected int memberCellNum = 3;

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	@Override
	protected Sdyx getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));

		String classess = ExcelUtil.formatCell(row.getCell(1));
//		String stepName = ExcelUtil.formatCell(row.getCell(2));
		String projectName = ExcelUtil.formatCell(row.getCell(2));

		Sdyx sdyx = new Sdyx();

		sdyx.setDate(date);
		sdyx.setClassess(translateClassess(classess));
		sdyx.setProjectName(projectName);
//		sdyx.setStep(translateStep(stepName));
		sdyx.setIsPass(0);
		sdyx.setTotalScore(this.getTotalScore(sdyx));
		return sdyx;
	}

	private int translateClassess (String classess){
		if (classess == null || classess.equals("")) {
			return 0;
		} else if (classess.equals("区域考核办公室（站点）")) {
			return 1;
		} else if (classess.equals("完成年度任务")) {
			return 2;
		} else {
			return 0;
		}
	}

	private Integer translateStep (String stepName){
		if (stepName == null || stepName.equals("")) {
			return 0;
		} else if (stepName.equals("试点负责人")) {
			return 1;
		} else if (stepName.equals("试点培训")) {
			return 2;
		} else if (stepName.equals("考核")) {
			return 3;
		} else {
			return 0;
		}
	}


	@Override
	public Double getTotalScore(Sdyx sdyx) {
		double result = 0.0;
		int classess = sdyx.getClassess();
//		int step = sdyx.getStep();
		if (classess == 1) {
			result = 50;
		} else if (classess == 2) {
			result = 20;
//			if (step == 1) {
//				result *= 0.4;
//			} else if (step == 2) {
//				result *= 0.3;
//			} else if (step == 3) {
//				result *= 0.3;
//			}
		}
		return result;
	}
	@Override
	public IPage<SdyxMemberPage> getSdyxMemberPageListByYear (String date, Integer pageNo, Integer pageSize){
		Page<SdyxMemberPage> page = new Page<>(pageNo, pageSize);
		return page.setRecords(this.baseMapper.selectSdyxMemberPageListByYear(date));
	}

	@Override
	public List<SdyxMemberPage> getSdyxMemberPageListByYear (String date){
		return this.baseMapper.selectSdyxMemberPageListByYear(date);
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(Sdyx jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(SdyxMemberPage.class, "classess", String.valueOf(jxcg.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}
		return result;
	}
}
